<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .current {
            font-weight: bold;
            color: orange;
        }
    </style>
</head>

<body>
    <div id="app">
        <h3>一、匿名插槽</h3>
        <alter-box>有bug发生</alter-box>
        <alter-box>有一个警告</alter-box>
        <alter-box></alter-box>

        <h3>二、具名插槽</h3>
        <p>写法一：</p>
        <base-layout>
            <p slot="header">标题信息</p>
            <p>主要内容1</p>
            <p>主要内容2</p>
            <p slot="footer">底部信息</p>
        </base-layout>

        <p>写法二：</p>
        <base-layout>
            <template slot="header">
                <p>标题信息</p>
            </template>
            <template>
                <p>主要内容1</p>
                <p>主要内容2</p>
            </template>
            <template slot="footer">
                <p>底部信息</p>
            </template>
        </base-layout>

        <h3>三、作用域插槽</h3>
        <fruit-list :list='list'>
            <template slot-scope="slotProps">
                <span :class='slotProps.info.id == 2 ? "current" : ""'>{{slotProps.info.name}}</span>
                <!-- <span class='current' v-if="slotProps.info.id==2">{{slotProps.info.name}}</span>
                <span v-else>{{slotProps.info.name}}</span> -->
            </template>
        </fruit-list>
    </div>
    <script src="js/vue.js"></script>
    <script>
        const alertBox = {
            template: `
                <div>
                    <b>ERROR: </b>
                    <slot>默认内容</slot>
                </div>
            `,
        };
        const baseLayout = {
            template: `
                <div>
                    <header>
                        <slot name='header'></slot>
                    </header>
                    <main>
                        <slot></slot>
                    </main>
                    <footer>
                        <slot name='footer'></slot>
                    </footer>
                </div>
            `,
        };
        const fruitList = {
            props: ['list'],
            template: `
                <div>
                    <ul>
                        <li :key='item.id' v-for='item in list'>
                            <slot :info='item'>{{item.name}}</slot>    
                        </li>
                    </ul>
                </div>
            `,
        };

        const vue = new Vue({
            el: '#app',
            data: {
                list: [{
                    id: 1,
                    name: 'apple'
                }, {
                    id: 2,
                    name: 'orange'
                }, {
                    id: 3,
                    name: 'banana'
                }, ],
            },
            components: {
                'alter-box': alertBox,
                'base-layout': baseLayout,
                'fruit-list': fruitList,
            }
        });
    </script>
    <div>

    </div>
</body>

</html>